package com.itjason.controller;

import com.itjason.dto.AdminLoginDTO;
import com.itjason.dto.NationUploadDataDTO;
import com.itjason.dto.RegionUpLoadDataDTO;
import com.itjason.exceptionhandler.ResponseException;
import com.itjason.service.WxAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Author:JasonLong
 * Date:2023/5/12
 * Time:9:22
 * 该控制类提供的接口为后台管理系统接口
 */
@Api(value = "管理员管理接口")
@RestController
@RequestMapping("/wx/admin")
public class WxAdminManagerController {

    @Autowired
    private WxAdminService wxAdminService;

    /**
     * 管理员注册接口
     *
     * @return ResponseException
     */
    @ApiOperation(value = "管理员注册接口")
    @ApiImplicitParam(name = "adminLoginDTO", value = "管理员信息,AdminLoginDTO实体类对象参数,返回数据为成功或者失败状态", dataType = "AdminLoginDTO", paramType = "form")
    @PostMapping("/adminRegister")
    public ResponseException adminRegister(@RequestBody AdminLoginDTO adminLoginDTO) {
        return wxAdminService.adminRegister(adminLoginDTO);
    }

    @ApiOperation(value = "管理员登录接口")
    @ApiImplicitParam(name = "adminLoginDTO", value = "管理员信息,AdminLoginDTO实体类对象参数,返回数据为成功或者失败状态", dataType = "AdminLoginDTO", paramType = "form")
    @PostMapping("/adminLogin")
    public ResponseException adminLogin(@RequestBody AdminLoginDTO adminLoginDTO) {
        return wxAdminService.adminLogin(adminLoginDTO);
    }


    /**
     * 该接口为管理员上传地区方言数据接口，为了能成功将数据映射到指定实体类中，所以
     * 参数命名应该与实体类的字段相同：multipartFile,nationAreaTranslation,nationAreaFlag
     */
    @ApiOperation(value = "管理员上传地区方言语音包接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nationAreaFlag", value = "地区标记", dataType = "String"),
            @ApiImplicitParam(name = "nationAreaTranslation", value = "方言中文意思", dataType = "String"),
            @ApiImplicitParam(name = "multipartFile", value = "语音包文件", dataType = "MultipartFile")
    })
    @PostMapping("/uploadRegion")
    public ResponseException uploadRegionalVoice(@RequestParam String nationAreaFlag, @RequestParam String nationAreaTranslation, @RequestParam MultipartFile multipartFile) {
        System.out.println(nationAreaFlag);
        RegionUpLoadDataDTO regionUpLoadDataDTO = new RegionUpLoadDataDTO();
        regionUpLoadDataDTO.setMultipartFile(multipartFile);
        regionUpLoadDataDTO.setNationAreaFlag(nationAreaFlag);
        regionUpLoadDataDTO.setNationAreaTranslation(nationAreaTranslation);
        System.out.println(regionUpLoadDataDTO);
        return wxAdminService.adminUploadRegion(regionUpLoadDataDTO);
    }


    /**
     * @param
     */
    @ApiOperation(value = "管理员上传民族方言语音包接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nationFlag", value = "民族标记", dataType = "String"),
            @ApiImplicitParam(name = "nationTranslation", value = "方言中文意思", dataType = "String"),
            @ApiImplicitParam(name = "multipartFile", value = "语音包文件", dataType = "MultipartFile")
    })
    @PostMapping("/uploadNation")
    public ResponseException uploadNationVoice(@RequestParam String nationFlag, @RequestParam String nationTranslation, @RequestParam MultipartFile multipartFile) {
        NationUploadDataDTO nationUploadDataDTO = new NationUploadDataDTO();
        nationUploadDataDTO.setNationFlag(nationFlag);
        nationUploadDataDTO.setNationTranslation(nationTranslation);
        nationUploadDataDTO.setMultipartFile(multipartFile);
        return wxAdminService.adminUploadNation(nationUploadDataDTO);
    }

    @ApiOperation(value = "管理员对语言包的删除")
    @PostMapping("/delete")
    public ResponseException deleteNation(@RequestBody Integer id){

        return wxAdminService.deleteById(id);
    }

}
